Skip to content

Commit 9d6f89f

Browse files
committed
Improve look and printability of new web ui
1 parent c0622da commit 9d6f89f

File tree

6 files changed

+82
-53
lines changed

6 files changed

+82
-53
lines changed

llamafile/server/www/chatbot.css

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
box-sizing: border-box;
55
}
66

7+
html,
8+
body {
9+
height: 100%;
10+
overflow-y: auto;
11+
}
12+
713
body {
814
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
915
line-height: 1.6;
@@ -17,14 +23,13 @@ p {
1723
}
1824

1925
.chat-container {
20-
max-width: 800px;
26+
max-width: 960px;
2127
margin: 2rem auto;
2228
background: white;
2329
border-radius: 12px;
2430
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
2531
display: flex;
2632
flex-direction: column;
27-
height: calc(100vh - 4rem);
2833
}
2934

3035
.chat-header {
@@ -248,38 +253,14 @@ ul li:first-child {
248253
display: block;
249254
}
250255

251-
.typing-indicator {
252-
display: none;
253-
align-items: center;
254-
gap: 0.25rem;
255-
padding: 0.5rem;
256-
color: #6c757d;
257-
}
258-
259-
.typing-indicator span {
260-
width: 4px;
261-
height: 4px;
262-
background: #6c757d;
263-
border-radius: 50%;
264-
display: inline-block;
265-
animation: typing 1s infinite ease-in-out;
266-
}
267-
268-
.typing-indicator span:nth-child(2) {
269-
animation-delay: 0.2s;
270-
}
271-
272-
.typing-indicator span:nth-child(3) {
273-
animation-delay: 0.4s;
274-
}
275-
276-
@keyframes typing {
277-
0%, 100% { transform: translateY(0); }
278-
50% { transform: translateY(-4px); }
279-
}
280-
281256
@media print {
282257

258+
html,
259+
body {
260+
height: auto !important;
261+
overflow-y: visible;
262+
}
263+
283264
.noprint {
284265
display: none;
285266
}
@@ -290,10 +271,14 @@ ul li:first-child {
290271

291272
.chat-container {
292273
box-shadow: none;
274+
height: auto !important;
275+
max-width: none !important;
276+
overflow: visible !important;
293277
}
294278

295279
.chat-header {
296280
border: none !important;
281+
page-break-inside: avoid;
297282
}
298283

299284
.chat-messages {

llamafile/server/www/chatbot.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const API_KEY = "your-api-key-here";
1818
const chatMessages = document.getElementById("chat-messages");
1919
const chatInput = document.getElementById("chat-input");
2020
const sendButton = document.getElementById("send-button");
21-
const typingIndicator = document.getElementById("typing-indicator");
2221
const stopButton = document.getElementById("stop-button");
2322

2423
let abortController = null;
@@ -44,11 +43,7 @@ function createMessageElement(content, role) {
4443
}
4544

4645
function scrollToBottom() {
47-
chatMessages.scrollTop = chatMessages.scrollHeight;
48-
}
49-
50-
function setTypingIndicatorVisibility(visible) {
51-
typingIndicator.style.display = visible ? "flex" : "none";
46+
chatInput.scrollIntoView({behavior: "instant"});
5247
}
5348

5449
function onChatInput() {
@@ -57,7 +52,6 @@ function onChatInput() {
5752
}
5853

5954
function cleanupAfterMessage() {
60-
setTypingIndicatorVisibility(false);
6155
chatMessages.scrollTop = chatMessages.scrollHeight;
6256
chatInput.disabled = false;
6357
sendButton.style.display = "inline-block";
@@ -144,9 +138,6 @@ async function sendMessage() {
144138
// update chat history
145139
chatHistory.push({ role: "user", content: message });
146140

147-
// show typing indicator
148-
setTypingIndicatorVisibility(true);
149-
150141
try {
151142
const response = await fetch(API_ENDPOINT, {
152143
method: "POST",
@@ -190,6 +181,7 @@ chatMessages.innerHTML = "";
190181
for (let i = 0; i < chatHistory.length; i++) {
191182
chatMessages.appendChild(createMessageElement(chatHistory[i].content,
192183
chatHistory[i].role));
184+
scrollToBottom();
193185
}
194186

195187
// setup events

llamafile/server/www/highlight_c.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,7 @@ class HighlightC extends Highlighter {
20282028
this.push('span', 'builtin');
20292029
this.append(this.word);
20302030
this.pop();
2031-
} else if (this.constants && this.constants(this.word)) {
2031+
} else if (this.constants && this.constants.has(this.word)) {
20322032
this.push('span', 'constant');
20332033
this.append(this.word);
20342034
this.pop();

llamafile/server/www/highlight_ruby.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,16 +682,19 @@ class HighlightRuby extends Highlighter {
682682
break;
683683

684684
case HighlightRuby.PERCENT_STRING:
685-
this.append(c);
686685
if (c == this.opener && this.opener != this.closer) {
686+
this.append(c);
687687
++this.level;
688688
} else if (c == '#') {
689689
this.state = HighlightRuby.PERCENT_HASH;
690690
} else if (c == this.closer) {
691+
this.append(c);
691692
if (!--this.level) {
692693
this.pop();
693694
this.state = HighlightRuby.NORMAL;
694695
}
696+
} else {
697+
this.append(c);
695698
}
696699
break;
697700

llamafile/server/www/index.html

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ <h1><img src="chatbot.png" alt="[logo]" width="64" height="64"> llamafile</h1>
1515
Loading...
1616
</div>
1717
</div>
18-
<div class="typing-indicator noprint" id="typing-indicator">
19-
<span></span>
20-
<span></span>
21-
<span></span>
22-
</div>
2318
<div class="chat-input-container noprint">
2419
<textarea class="chat-input" id="chat-input" placeholder="Type your message..." rows="1" autocomplete="off"></textarea>
2520
<button class="send-button" id="send-button">Send</button>

llamafile/server/www/test/test.md

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,15 @@ int main() {
6262
years old." << std::endl;`:** This line prints a message to the
6363
console. Let's break it down:
6464
- `std::cout` is the standard output stream object.
65-
- `<<` is the insertion operator, used to send data to the output stream.
66-
- `"Hello, world! My name is AI, and I am "` is a string literal that will be printed as is.
67-
- `age` is the variable we declared earlier. Its value (25) will be inserted into the output stream.
65+
- `<<` is the insertion operator, used to send data to the output
66+
stream.
67+
- `"Hello, world! My name is AI, and I am "` is a string literal that
68+
will be printed as is.
69+
- `age` is the variable we declared earlier. Its value (25) will be
70+
inserted into the output stream.
6871
- `" years old."` is another string literal.
69-
- `std::endl` inserts a newline character, moving the cursor to the next line for any subsequent output.
72+
- `std::endl` inserts a newline character, moving the cursor to the
73+
next line for any subsequent output.
7074

7175
5. **`return 0;`:** This line indicates that the program executed
7276
successfully. Returning 0 from the `main` function is a convention in
@@ -161,3 +165,53 @@ part of the code.
161165
This program is a simple example of how to use variables, input/output
162166
operations, conditional statements, and loops in FORTRAN66. It
163167
demonstrates basic input/output operations and error handling.
168+
169+
## Rubby
170+
171+
```ruby
172+
# comment
173+
42
174+
"String with #{ :interpolation }"
175+
/regex$/
176+
$/
177+
[?😀, ?\ , ?', ?(] ?'a':'b'
178+
"%d %d %d"%[1,2,3]
179+
% 5 #
180+
181+
/
182+
$$#$/
183+
/omix
184+
185+
puts <<HERE<<<<THERE
186+
foo 42
187+
HERE
188+
bla 43
189+
THERE
190+
191+
puts "This is #{<<HERE.strip} evil"
192+
incredibly
193+
HERE
194+
195+
def `
196+
`hello` / /regex/
197+
end
198+
199+
"hi #$" there" a
200+
"hi #$abc there" a
201+
"hi #{hi} there" a
202+
/hi #$" there/ a
203+
/hi #$abc there/ a
204+
/hi #{hi} there/ a
205+
_=;"#$q"
206+
207+
# Examples:
208+
%q(Don't worry) # => "Don't worry"
209+
%Q(Today is #{Date.today}) # => "Today is 2024-11-08"
210+
%r{^/path/to/\w+} # => /^\/path\/to\/\w+/
211+
%s(my_symbol) # => :my_symbol
212+
%w(foo bar baz) # => ["foo", "bar", "baz"]
213+
%W(foo #{1+1} baz) # => ["foo", "2", "baz"]
214+
%x(ls -l) # Executes `ls -l` and returns output
215+
%i(foo bar baz) # => [:foo, :bar, :baz]
216+
%I(foo#{1+1} bar baz) # => [:foo2, :bar, :baz]
217+
```

0 commit comments

Comments
 (0)